const app = getApp();
import { zg99Request, hbappRequest, jiatuiRequest } from "/utils/requests";
Page({

  /**
   * 页面的初始数据
   */
  data: {
    showContact: true,
    suspendShow: true,
    showIcon: true,
    bgcolor: '',
    file: [],
    yl: 1,
    form: true,
    table: false,
    gonghao: '无',
    fenxiao: '无',
    xiangmu: 'sk',
    lx: 'sk',
    laiyuan: '专业分类',
    zwcxbg: '',
    showIcon: !0,
    isShowCdNav: !1,
    majorvalue: '',
    zhuanye_datalist: [],
    actid: 17122,
    open_menu: false,
    animationData: {},
    animationData1: {},
    animationData2: {},
    menu_is_open: '',
    skheight: 0,
    display: 'none',
    padding: 0,
    lx: "sk",
    xiangmuok: false,
    bklx: [{
      id: "5_1",
      text: "综合岗"
    }, {
      id: "5_2",
      text: "教育岗"
    }, {
      id: "5_3",
      text: "医疗岗"
    }],
    bklxvalue: '',
    myPhone: '',
    listId: 0,
    lists: [{
        'title': '按专业名称查询',
        "zt": 'on'
    }, {
        'title': '按一级学科查询',
        "zt": ''
    }],
  },
  m_selectSearch_touch: function (t) {
    var e = t.detail.selText;
    var newList = t.detail.selectList;
    this.setData({
      majorvalue: e,
      zhuanye_datalist: newList
    });
  },
  m_select_touch: function (t) {
    var e = t.detail.selIndex,
      a = t.detail.stype;
    if ("51" == a) {
      var a5 = this.data.bklx[e];
      this.setData({
        bklxvalue: a5.text
      });
    }
    // console.log(this.data.bklxvalue)
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: async function (options) {
    this.setData(await app.methods.myPhone()); // 获取本地存储手机号
    console.log(this.data)
    if(!this.data.myPhone) {
      await app.methods.getPhoneNumber()
      this.setData({
        isShowAuth: !0
      })
  }
    xhs.showShareMenu({
      shareTypes: 'normal',
    })
    let links, jxOptions;
    if (options.scene) {
      options.scene = options.scene.replace(/%253D/g, ".");
      options.scene = options.scene.replace(/%2526/g, "-");
        jxOptions = await app.methods.getOPtions(options);
    }
    let id = options.scene ? jxOptions.id : options.id;
    options.id = id;
    links = await app.methods.getLink(id);
    options.yl = links.yl ? links.yl : '';
    options.s1 = links.s1 ? links.s1 : 'y';
    options.lx = links.lx ? links.lx : '';
    options.xiangmu = links.xiangmu ? links.xiangmu : '';
    options.fx = options.scene ? jxOptions.fx : options.fx;
    options.gh = options.scene ? jxOptions.gh : options.gh;
    if (options.lx != undefined) {
      if (options.lx.length > 0) {
        this.setData({
          isSydw: true,
          lx: options.lx
        })
      }
    } 
    if (options.yl != undefined) {
      if (options.yl.length > 0) {
        this.setData({
          yl: Number(options.yl)
        })
      }
    }
    this.setData(await app.methods.getIdentity(options)); // 获取个人身份信息
    if(this.data.getIdentity.crm) {
        options.wxh = this.data.getIdentity.crm;
    } else {
        options.wxh = options.gh;
    }
    this.setData(await app.methods.getWechat(options)); // 获取个人身份信息
    this.setData(await app.methods.guishudi(options)); // 获取归属地
    let fenbu = this.data.fenbu;
    let fenxiao = this.data.fenxiao;
    let getIdentity = this.data.getIdentity;
    getIdentity.fenbu = fenbu;
    getIdentity.fenxiao = fenxiao;
    getIdentity.zzname = this.data.zzname;
    getIdentity.zzid = this.data.zzid;
    getIdentity.erpdqm = this.data.erpdqm;
    this.setData({
      options,
      getIdentity
    })
    await this.getHD();
    this.data.myPhone == '' ? '' : this.setData(await app.methods.getphonestatusCX(this.data.myPhone, this.data.actid, 'chaxun'))
    //查询是否注册并且返回user信息
    this.thisMethod()
    // if(this.data.myPhone) {
    //   this.setData(await app.methods.getphonestatusCX(this.data.myPhone, this.data.actid, 'chaxun'))
    // }
    // this.thisMethod()
    // this.getUser()
    // console.log(this.data)
  },
  clickfn: async function () {
    if (!this.data.myPhone) {
      this.setData({
        isShowAuth: !0,
      })
      return false
    }
    if (this.data.majorvalue == '') {
      xhs.showToast({
        title: '请输入问题',
        icon: 'none',
        duration: 2000
      })
      return false
    }
    if ((this.data.xiangmuok) && (this.data.lx == 'sydw') && (this.data.bklxvalue == '')) {
      xhs.showToast({
        title: '请选择备考类型',
        icon: 'none',
        duration: 2000
      })
      return false
    }
    await this.getUser()
    xhs.showLoading({
      title: '数据查询中',
    })
    xhs.hideLoading()
    xhs.showToast({
      title: '数据查询成功!',
      icon: 'success',
      duration: 2000
    })
    this.setData({
      form: false,
      table: true,
      xiangmuok: false
    })
  },
  gksw: function(){
    xhs.navigateTo({
      url: `/packageB/gg/gg?link=https://hb.offcn.com/html/2023/10/286347.html`,
    })
  },
  open_menu: function () {
    var animation1 = xhs.createAnimation({
      duration: 1000,
      timingFunction: "ease",
    })
    var animation2 = xhs.createAnimation({
      duration: 1000,
      timingFunction: "ease",
    })
    var animation3 = xhs.createAnimation({
      duration: 1000,
      timingFunction: "ease",
    })
    var animation4 = xhs.createAnimation({
      duration: 1000,
      timingFunction: "ease",
    })
    var animation5 = xhs.createAnimation({
      duration: 1000,
      timingFunction: "ease",
    })
    var animation6 = xhs.createAnimation({
      duration: 1000,
      timingFunction: "ease",
    })
    this.animation = animation1
    this.animation = animation2
    this.animation = animation3
    this.animation = animation4
    this.animation = animation5
    this.animation = animation6
    animation1.width('620rpx').height('600rpx').step();
    animation2.width('0rpx').height('0rpx').step();
    animation3.rotate(360).step();
    animation4.rotate(0).step();
    animation5.width('25%').scale(1).step();
    animation6.width('0rpx').scale(0).step();
    if (this.data.open_menu) {
      this.setData({
        open_menu: false,
        menu_is_open: '',
        padding: 0,
        animationData: animation2.export(),
        animationData1: animation4.export(),
        animationData2: animation6.export(),
      })
    } else {
      this.setData({
        open_menu: true,
        menu_is_open: 'menu-is-open',
        padding: 40,
        animationData: animation1.export(),
        animationData1: animation3.export(),
        animationData2: animation5.export(),
      })
    }
  },
  changetj: function () {
    this.setData({
      table: false,
      form: true
    })
  },
  // 该怎么就怎么
  thisMethod: function () {
    if (this.data.user && this.data.user.status == 1) {
      if (!this.data.user.user.gwlb && this.data.options.lx == 'sydw') {
        this.setData({
          xiangmuok: true
        })
      }
      if (!this.data.user.user.zhunkaozheng && this.data.ms == 0) {
        this.setData({
          zhunkaozhengok: true
        })
      } else {
        this.setData({
          zhunkaozhengok: false
        })
      }
    } else {
      if (this.data.options.lx == 'sydw') {
        this.setData({
          xiangmuok: true
        })
      }
    }
  },
  // 学员信息查询 
  async getUser() {
    if (this.data.myPhone != '') {
      if (!this.data.user) {
        await app.methods.registerCX(this.data.myPhone, this.data.actid, this.data.laiyuan, this.data.isSydw, this.data.getIdentity, this.data.bklxvalue, '', '', 'chaxun')
        if (this.data.lx != 'sydw') {
          this.setData({
            ['user.user.laiyuan']: this.data.laiyuan
          })
        }
      } else {
        let laiyuan = this.data.user.user.laiyuan;
        if (this.data.lx == 'sydw') {
          var bklxvalue = this.data.user.user.gwlb;
        }
        if (laiyuan.indexOf(this.data.laiyuan) < 0) {
          await app.methods.updateuserCX(this.data.myPhone, this.data.actid, this.data.laiyuan, this.data.isSydw, this.data.getIdentity, this.data.bklxvalue, '', 'chaxun', '', this.data.user.user)
          this.setData({
            ['user.laiyuan']: this.data.laiyuan
          })
        } else if (this.data.lx == 'sydw' && !bklxvalue) {
          await app.methods.updateuserCX(this.data.myPhone, this.data.actid, this.data.laiyuan, this.data.isSydw, this.data.getIdentity, this.data.bklxvalue, '', 'chaxun', '', this.data.user.user)
          this.setData({
            ['user.gwlb']: this.data.bklxvalue
          })
        }
      }
    }
  },
  // 获取活动信息
  async getHD() {
    return new Promise((resolve) => {
      zg99Request({
        url: '/index/chaxun/getfzinfo/?actid=43261&callback=&',
        method: 'GET',
        dataType: 'jsonp',
        data: {
          time: Date.parse(new Date()) / 1000,
          xiangmu: this.data.options.xiangmu,
        },
      }).then(res => {
        let newStr = app.methods.getAPIReturn(res);
        this.setData({
          actid: Number(newStr.lists[0].form),
          shareImg: newStr.lists[0].shareImg,
          shareFont: newStr.lists[0].shareFont,
        })
        app.globalData.laiyuan = `${this.data.options.xiangmu}${this.data.laiyuan}`
        resolve()
      }).catch(err => {
        console.log(err)
        resolve()
      })
    })
  },
  // 切换“按个人条件查询”与“按职位信息查询”
  recoveryState: function (e) {
    const { id, dataset } = e.currentTarget;
    if (id == 'on') return false;
    const { lists } = this.data;
    lists[dataset.num].zt = 'on'
    dataset.num == 0 ? lists[1].zt = '' : lists[0].zt = ''
    this.setData({
      lists,
      listId: dataset.num
    })
  },
  async user_login(e){
      if(typeof e.detail == 'boolean') {
          this.setData({
              isShowAuth: e.detail
          })
      } else {
          this.setData({
              myPhone: e.detail
          })
          this.setData(await app.methods.getphonestatusCX(this.data.myPhone, this.data.actid, 'chaxun'));
          await this.thisMethod();
      }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return {
      imageUrl: this.data.shareImg ? this.data.shareImg : '',
      title: this.data.shareFont ? this.data.shareFont : "河北公职考试专业分类查询_河北中公教育",
      path: "/pages/zhuanye/zhuanye?id=" + this.data.options.id + '&gh=' + this.data.options.gh + '&fx=' + this.data.options.fx,
      success: function (t) {
        console.log(t, "转发成功");
      },
      fail: function (t) {
        console.log(t, "转发失败");
      }
    };
  }
})